package inits

import (
	"fmt"
	"github.com/go-redis/redis/v8"
	"zk2/config"
	"zk2/globals"
)

func InitRedis() {
	redisConfig := config.AppConfig.Redis
	Addr := fmt.Sprintf("%s:%d", redisConfig.Host, redisConfig.Port)
	globals.Rdb = redis.NewClient(&redis.Options{
		Addr:     Addr,
		Password: redisConfig.Password,
		DB:       0,
	})
	err := globals.Rdb.Ping(globals.Ctx).Err()
	if err != nil {
		panic(err)
	} else {
		fmt.Println("redis 连接成功")
	}
}
